package com.focusai.efairy.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.focusai.efairy.R;

/**
 * Created by luo_guangwen on 2017/7/31.
 */

public class TitleView extends LinearLayout {
    private ImageView mBack;
    private TextView mTextCenter;
    private TextView mTextLeft;
    private TextView mTextLeft2;
    private TextView mTextRight;
    private TextView mTextRight1;
    private RadioGroup mRadioGroup;
    private RadioButton mRbnLeft;
    private RadioButton mRbnRight;
    public TitleView(Context context) {
        super(context);
    }

    public TitleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        initView(context,attrs);
    }

    public TitleView(Context context, AttributeSet attrs, int defStryle) {
        super(context, attrs, defStryle);
        initView(context,attrs);
    }

    private void initView(Context context, AttributeSet attrs) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.view_tittle, this);
        mBack = (ImageView) view.findViewById(R.id.img_title_left);
        mTextCenter = (TextView) view.findViewById(R.id.text_title_center);
        mTextRight = (TextView) view.findViewById(R.id.text_title_right);
        mTextRight1 = (TextView) view.findViewById(R.id.text_title_right1);
        mTextLeft = (TextView) view.findViewById(R.id.text_title_left);
        mTextLeft2 = (TextView) view.findViewById(R.id.text_title_left2);
        mRadioGroup = (RadioGroup) view.findViewById(R.id.title_radiogroup);
        mRbnLeft = (RadioButton) view.findViewById(R.id.title_radio_btn_left);
        mRbnRight = (RadioButton) view.findViewById(R.id.title_radio_btn_right);

        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.title_style);
        if (array != null){
            CharSequence centerText = array.getString(R.styleable.title_style_center_text);
            CharSequence rightText = array.getString(R.styleable.title_style_right_text);
            mTextRight.setText(rightText);
            mTextCenter.setText(centerText);
            mTextCenter.setTextColor(array.getColor(R.styleable.title_style_center_font_color,getResources().getColor(R.color.main_title_black)));
            mTextRight.setTextColor(array.getColor(R.styleable.title_style_right_font_color,getResources().getColor(R.color.main_title_black)));
            Drawable rightDrawable = array.getDrawable(R.styleable.title_style_right_bg);
            mTextRight.setBackgroundDrawable(rightDrawable);
            boolean isLeftVisible = array.getBoolean(R.styleable.title_style_left_visible, true);
            boolean isRightVisible = array.getBoolean(R.styleable.title_style_right_visible, true);
            if (isLeftVisible){
                mBack.setVisibility(VISIBLE);
            }else {
                mBack.setVisibility(GONE);
            }
            if (isRightVisible){
                mTextRight.setVisibility(VISIBLE);
            }else {
                mTextRight.setVisibility(GONE);
            }
            array.recycle();
        }

    }

    public ImageView getmBack() {
        return mBack;
    }

    public TextView getmTextCenter() {
        return mTextCenter;
    }

    public TextView getmTextRight() {
        return mTextRight;
    }

    public TextView getmTextLeft() {
        return mTextLeft;
    }

    public TextView getmTextLeft2() {
        return mTextLeft2;
    }

    public TextView getmTextRight1() {
        return mTextRight1;
    }

    public RadioGroup getmRadioGroup() {
        return mRadioGroup;
    }

    public void setmRadioGroup(RadioGroup mRadioGroup) {
        this.mRadioGroup = mRadioGroup;
    }

    public RadioButton getmRbnLeft() {
        return mRbnLeft;
    }

    public void setmRbnLeft(RadioButton mRbnLeft) {
        this.mRbnLeft = mRbnLeft;
    }

    public RadioButton getmRbnRight() {
        return mRbnRight;
    }

    public void setmRbnRight(RadioButton mRbnRight) {
        this.mRbnRight = mRbnRight;
    }
}
